package com.itheima.controller;

import com.itheima.R;
import com.itheima.service.PmsProductAttributeCategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chensen
 * @create 2022/10/12/20:13
 */

@RestController
@RequestMapping("productAttribute/category")
public class PmsProductAttributeCategoryController {
    @Autowired
    private PmsProductAttributeCategoryService pmsProductAttributeCategoryService;
    /**
     * 添加商品属性分类
     * @param name
     * @return
     */
    @PostMapping("create")
    public R create(@RequestParam String name){
        return pmsProductAttributeCategoryService.create(name);
    }

    /**
     * 删除单个商品属性分类
     * @param id
     * @return
     */
    @GetMapping("delete/{id}")
    public R delete(@PathVariable Long id){
        return pmsProductAttributeCategoryService.delete(id);
    }

    /**
     * 分页获取所有商品属性分类
     * @param pageSize
     * @param pageNum
     * @return
     */
    @GetMapping("list")
    public R getList(@RequestParam(defaultValue = "5") Integer pageSize, @RequestParam(defaultValue = "1") Integer pageNum){
        return pmsProductAttributeCategoryService.list(pageNum,pageSize);
    }

    /**
     * 获取所有商品属性分类及其下属性
     * @return
     */
    @GetMapping("list/withAttr")
    public R getAll(){
        return pmsProductAttributeCategoryService.getAll();
    }

    /**
     * 修改商品属性分类
     * @param id
     * @param name
     * @return
     */
    @PostMapping("update/{id}")
    public R update(@PathVariable Long id, @RequestParam String name){
        return pmsProductAttributeCategoryService.update(id,name);
    }

    /**
     * 获取单个商品属性分类信息
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public R getItem(@PathVariable Long id){
        return pmsProductAttributeCategoryService.getItem(id);
    }


}
